package com.jiulong.controller;

import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.alibaba.fastjson.JSONObject;

import com.jiulong.common.utils.StringUtil;
import com.jiulong.service.ProductService;


@Controller
public class ljpControl extends BaseController{

	@Autowired
	ProductService productService;
	
	@RequestMapping(value="/kfyd",method=RequestMethod.GET)
	public String kfyd(HttpServletRequest request,HttpServletResponse response,Model model) throws Exception{
	try{
		HttpSession session=request.getSession();
		session.getAttribute("openid");
		
	}catch(Exception e){
		
	}
        List list=productService.findProductByDefault(null);
    
        
        model.addAttribute("detailList", list);
        	return "kfyd";
	}
	
	@RequestMapping(value="/kfydFenye",method=RequestMethod.GET)
	public String kfydFenye(HttpServletRequest request,HttpServletResponse response,Model model) throws Exception{

        List list=productService.findProductByDefault(null);
/*        model.addAttribute("currentPage", 2);
        model.addAttribute("totalPage", 20);
        model.addAttribute("pageSize", 2);
        model.addAttribute("totalRows", 100);
        */   
        model.addAttribute("detailList", list);
        	return "kfyd2";
	}
	
	@RequestMapping(value="/kfydLone",method=RequestMethod.GET)
	public String kfyLone(HttpServletRequest request,HttpServletResponse response,Model model) throws Exception{     
		List list=null;
		try{
		String productName =new String(request.getParameter("productName").getBytes("iso8859-1"),"utf-8");
	 	list=productService.findProductLone(productName);
	}catch(Exception e){
		e.printStackTrace();
	}
        model.addAttribute("detailList", list);
        	return "kfydLone";
	}
	
	@RequestMapping(value="/kfyd",method=RequestMethod.POST)
	public String postkfyd(String city,String startDate,String endDate,HttpServletRequest request,HttpServletResponse response,Model model) throws IOException, ParseException{
		//String  publicDada =request.getParameter("publicDada");
		 String title=request.getParameter("title");
	        //String a[] = publicDada.split(",");  
	       /* int breakfirst = 0 ; int park = 0 ; int meettingRoom = 0 ;int wifi = 0 ;int visitor = 0 ;
			for (String b : a) {
				
				if(b.equals("早餐")){
					 breakfirst=1;	
					
				}		
				if(b.equals("停车场")){
					 park=1;						 
				}
				if(b.equals("会议室")){
					 meettingRoom=1;		
				}
				if(b.equals("客房wifi")){
					 wifi=1;		
				}
				if(b.equals("接待外宾")){
					 visitor=1;		
				}
			}
*/
	         
		String city1=null;
		if(!StringUtil.isBlank(city)){
			String c[]=city.split(" ");
			city=c[0];
			city1=c[1];
			if(city.length()>2){
				city=city.substring(0, 2);
			}
		}else{
			return "kfyd";
		}
		Date sd=null;
		Date ed=null;
		if(!StringUtil.isBlank(startDate)&&!StringUtil.isBlank(endDate)){
			SimpleDateFormat sdf2  = new SimpleDateFormat("yyyy-MM-dd");
			sd=sdf2.parse(startDate);
			ed=sdf2.parse(endDate);
		}
		
		HashMap param=new HashMap();
		param.put("city", city);
		param.put("city1", city1);
		param.put("startDate",sd);
		param.put("endDate", ed);
		param.put("title", title);
	
		
		
	//	param.put("breakfirst", breakfirst);
		//param.put("park", park);
		//param.put("meettingRoom", meettingRoom);
	//param.put("wifi", wifi);
		//param.put("visitor", visitor);
		
	/*	Object o=breakfirst!=null?param.put("breakfirst",breakfirst.equals("on")?1:0):param.put("breakfirst", 0);
		o=park!=null?param.put("park",park.equals("on")?1:0):param.put("park", 0);
		o=meettingRoom!=null?param.put("meettingRoom",meettingRoom.equals("on")?1:0):param.put("meettingRoom", 0);
		o=wifi!=null?param.put("wifi",wifi.equals("on")?1:0):param.put("wifi", 0);
		o=visitor!=null?param.put("visitor",visitor.equals("on")?1:0):param.put("visitor", 0);*/
		
		List list=productService.findProductBysele(param);
		model.addAttribute("detailList", list);
		
		return "kfyd";
	}
	
	
	
	//┏┓　　　┏┓
	//┏┛┻━━━┛┻┓
	//┃　　　　　　　┃ 　
	//┃　　　━　　　┃
	//┃　┳┛　┗┳　┃
	//┃　　　　　　　┃
	//┃　　　┻　　　┃
	//┃　　　　　　　┃
	//┗━┓　　　┏━┛
//	    ┃      ┃
	//┃　　　┃  神兽保佑　　　　　　　　
	//┃　　　┃  代码无BUG！
	//┃　　　┗━━━┓
	//┃　　　　　　　┣┓
	//┃　　　　　　　┏┛
	//┗┓┓┏━┳┓┏┛
	// ┃┫┫　┃┫┫
	// ┗┻┛　┗┻┛

	@RequestMapping(value="/AccountAction",method=RequestMethod.GET)
	public void UserLocaltion(HttpServletRequest request,HttpServletResponse response)throws Exception{
		String account=request.getParameter("account");
		String password=request.getParameter("password");
		System.out.println(account);
	
	}
	
	public  static void main(String[] args){
		String a="{\"access_token\":\"PoCvKVoJsCNZsnpfAs4o8iC6tIV2HMDYAzFjQsT1HbYXKl1lpyXpMA3Xa6c2vr3e6VBVvXJCBzvgNwCD9tURj2Yp2VHbajtVwaMRpO-jDJ8\",\"expires_in\":7200,\"refresh_token\":\"9kJ76ABbt58dr9k295FIM2M78vEG8JNzii3V-gI5FsRLSCvPPVqpfy7ug5TBhor1BIp4TiYO71hWN1zn5FMLnNhWHwB-B63DYTNoBFUJRXo\",\"openid\":\"ohx_wwiIXSM7yFNDcaLymiMeIh8o\",\"scope\":\"snsapi_userinfo\"}";
		JSONObject j=JSONObject.parseObject(a);
		System.out.println(j.get("access_token"));
	}
	
	

}
